package com.newcapec.news.servlet;

import com.newcapec.news.entity.Channel;
import com.newcapec.news.entity.SysUser;
import com.newcapec.news.service.ChannelService;
import com.newcapec.news.service.impl.ChannelServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Description: 登录页面的展示
 * @Author: fujun
 * @Date : 2022/3/16 16:08
 * @Version : 1.0
 * @company 新开普电子股份有限公司
 */
@WebServlet("/page/AddNews.html")
public class ShowAddNewsHtmlServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//            req.setCharacterEncoding("utf-8");
//            resp.setCharacterEncoding("utf-8");
        //跳转添加新闻的jsp页面    我们给jsp页面传递一些数据 

        SysUser user= (SysUser) req.getSession().getAttribute("user");

        if(user==null){


            return ;
        }
        ChannelService channelService=new ChannelServiceImpl();

        List<Channel> channels = channelService.queryChannel(user.getId());

        //通过请求域的共享属性 ，传递给jsp页面
        req.setAttribute("channels",channels);
        req.getRequestDispatcher("../WEB-INF/page/AddNewsManagement.jsp").forward(req,resp);


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
